<?php

include_once(dirname(__FILE__) . '/mobily_sms/includeSettings.php');

class globals {

    /**
     * send sms message to the specified phone number
     * @param string $msg
     * @param numberOrArray $phone_nums 
     */
    public static function send_sms($msg, $phone_nums) {
        if (!is_array($phone_nums)) {
            $phone_nums = array($phone_nums);
        }
        $msg = iconv('UTF-8', 'Windows-1256', $msg); // fix problem of ANSI
        //var_dump(sfContext::getInstance()->getConfiguration()->getEnvironment());exit;
        if (sfContext::getInstance()->getConfiguration()->getEnvironment() == 'dev') { // for test mode            
            $phone_nums = sfConfig::get('app_test_phone_rec', array('00962797117177', '00962788657369'));
        }
        $numbers = $phone_nums;
        $numbers = implode(',', $numbers);

        $MsgID = rand(1, 1000000);
        $sender = sfConfig::get('app_mobily_settings_sender_name');
        $mobile = sfConfig::get('app_mobily_settings_sender_mobile');
        $password = sfConfig::get('app_mobily_settings_sender_password');

        $timeSend = 0;
        $dateSend = 0;
        $deleteKey = 43323; // no use
        $resultType = 24;

        sendSMS($mobile, $password, $numbers, $sender, $msg, $MsgID, $timeSend, $dateSend, $deleteKey, $resultType);
    }

    /**
     *
     * @param string $date 
     * @return string $hijree_date
     */
    public static function getHijreeDate($date) {
        list($year, $month, $day) = explode('-', $date);
        $months_arr = array(
            1 => 'محرم', 2 => 'صفر', 3 => 'ربيع الأول', 4 => 'ربيع الآخر', 5 => 'جمادى الأولى', 6 => 'جمادى الآخرة', 7 => 'رجب', 8 => 'شعبان', 9 => 'رمضان', 10 => 'شوال', 11 => 'ذو القعدة', 12 => 'ذو الحجة',
        );

        return $day . ' - ' . (int) $month . ' - ' . $year;
        //return $day . ' - ' . $months_arr[(int) $month] . ' - ' . $year;
    }

    public static function wordify($html) {
        return '<html xmlns:v="urn:schemas-microsoft-com:vml"xmlns:o="urn:schemas-microsoft-com:office:office"xmlns:w="urn:schemas-microsoft-com:office:word"xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=ProgId content=Word.Document><meta name=Generator content="Microsoft Word 9"><meta name=Originator content="Microsoft Word 9"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}o\:* {behavior:url(#default#VML);}w\:* {behavior:url(#default#VML);}.shape {behavior:url(#default#VML);}</style><![endif]--><title></title><!--[if gte mso 9]><xml> <w:WordDocument><w:View>Print</w:View><w:DoNotHyphenateCaps/><w:PunctuationKerning/><w:DrawingGridHorizontalSpacing>9.35 pt</w:DrawingGridHorizontalSpacing><w:DrawingGridVerticalSpacing>9.35 pt</w:DrawingGridVerticalSpacing></w:WordDocument></xml><![endif]--><!--[if gte mso 9]><xml><o:shapedefaults v:ext="edit" spidmax="1032"><o:colormenu v:ext="edit" strokecolor="none"/></o:shapedefaults></xml><![endif]--><!--[if gte mso 9]><xml><o:shapelayout v:ext="edit"><o:idmap v:ext="edit" data="1"/></o:shapelayout></xml><![endif]--></head><body>' . $html . '</body></html>';
    }

    public static function getRandomColorHex($max_r = 200, $max_g = 200, $max_b = 200) {
        if ($max_r > 255) {
            $max_r = 255;
        }
        if ($max_g > 255) {
            $max_g = 255;
        }
        if ($max_b > 255) {
            $max_b = 255;
        }
        if ($max_r < 0) {
            $max_r = 0;
        }
        if ($max_g < 0) {
            $max_g = 0;
        }
        if ($max_b < 0) {
            $max_b = 0;
        }

        // generate and return the random color
        return str_pad(dechex(rand(50, $max_r)), 2, '0', STR_PAD_LEFT) .
        str_pad(dechex(rand(50, $max_g)), 2, '0', STR_PAD_LEFT) .
        str_pad(dechex(rand(50, $max_b)), 2, '0', STR_PAD_LEFT);
    }

}